<template>
  <view class="container-box">
    <view class="login-box">
      <view class="no-info"><u-icon name="account-fill" color="#fff" size="100"></u-icon></view>
      <button type="primary" class="btn-login" open-type="getUserInfo" @getuserinfo="getUserInfo">一键登录</button>
    </view>
    <u-modal :show="show" title="提示" content='请先阅读并勾选服务协议'></u-modal>
    <view class="agreement-box">
      <view class="agreement">
        <checkbox :value="value"  @click="getShow" /><text>阅读并同意</text>
        <navigator class="article" url="/pages/login/login">用户协议、</navigator>
        <navigator class="article" url="/pages/login/login">隐私政策、</navigator>
        <navigator class="article" url="/pages/login/login">服务监督协议</navigator>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        value:false,
        show:false,
        infoData:{}
      };
    },
    methods: {
      getUserInfo(e) {
        if(!this.value) return wx.showModal({
            title: '提示',
            content: '请先阅读并勾选服务协议',
          })
          // 判断是否获取用户信息成功
        if (e.detail.errMsg === 'getUserInfo:fail auth deny') return uni.$showMsg('您取消了登录授权！')
        
        // 获取用户信息成功， e.detail.userInfo 就是用户的基本信息
        this.infoData['nickName']=e.detail.userInfo.nickName
        this.infoData['avatarUrl']=e.detail.userInfo.avatarUrl
        uni.setStorageSync('info',JSON.stringify(this.infoData))
        this.getToken(e.detail)
        
        },
        async getToken(info) {
          // 调用微信登录接口
          const [err, res] = await uni.login().catch(err => err)
          // console.log(res)
          // 判断是否 uni.login() 调用失败
          if (err || res.errMsg !== 'login:ok') return uni.$showError('登录失败！')
        
          // 准备参数对象
          const query = {
            code: res.code,
            encryptedData: info.encryptedData,
            iv: info.iv,
            rawData: info.rawData,
            signature: info.signature
          }
        //   console.log(query)
        uni.switchTab({
          url:'/pages/navigation/my'
        })
        },
        getShow(){
          if(this.value){
            this.value = false
          }else{
            this.value = true
          }
        }
    },
  }
</script>

<style lang="scss">
  .container-box{
    height: 100%;
  }
  body{
    height: 100%;
  }
  .login-box{
    height: 60%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f6f9f6;
    border-radius: 0 0 50px 50px;
      .btn-login{
        width: 80%;
        margin-top: 15px;
        border-radius: 25px;
        background-color: #54bcbd;
      }
    .no-info {
      margin-buttom: 15px;
      display: flex;
      width: 80px;
      height: 80px;
      border-radius: 40px;
      background: #adafad;
      justify-content: center;
      align-items: center;
      
      .nomy-info {
        padding: 0 24px;
        display: flex;
        align-items: center;
      }
    }
  }
    .agreement-box{
      padding-bottom: 20px;
      height: 40%;
      display: flex;
      align-items: flex-end;
      justify-content: center;
      .agreement{
        display: flex;
        align-items: center;
        font-size: 12px;
        .article{
          color: blue;
        }
      }
    }
</style>
